<template>
  <div class="app-container">
<el-card class="box-card">
  <div slot="header" class="clearfix">
    <span>企业系统配置</span>
    <el-button style="float: right; padding: 3px 0" type="text" @click="submitForm()" >保存设置</el-button>
  </div>
  <el-row>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px" >
           <el-form-item label="公司名称" prop="companyName">
             <el-input v-model="form.companyName" placeholder="请输入公司名称" />
             <span style="color: red;">注：公司名称作为登录的身份识别的其一条件，修改公司名称，登录系统也要使用新的公司名称</span>
           </el-form-item>
           <el-form-item label="联系人" prop="companyContacts">
             <el-input v-model="form.companyContacts" placeholder="请输入联系人" />
           </el-form-item>
           <el-form-item label="公司地址" prop="companyAddress">
             <el-input v-model="form.companyAddress" placeholder="请输入公司地址" />
           </el-form-item>
           <el-form-item label="公司电话" prop="companyTel">
             <el-input v-model="form.companyTel" placeholder="请输入公司电话" />
           </el-form-item>
           <el-form-item label="公司传真" prop="companyFax">
             <el-input v-model="form.companyFax" placeholder="请输入公司传真" />
           </el-form-item>
           <el-form-item label="公司邮编" prop="companyPostCode">
             <el-input v-model="form.companyPostCode" placeholder="请输入公司邮编" />
           </el-form-item>
          <el-form-item label="仓库权限" prop="depotFlagSwitch">
            <!-- <el-input v-model="form.depotFlag" placeholder="请输入仓库启用标记，0未启用，1启用" /> -->
             <el-switch
               v-model="depotFlagSwitch"
               active-color="#13ce66"
               inactive-color="#ff4949">
             </el-switch>
             （如果启用则需要到用户管理进行分配仓库）
           </el-form-item>
           <el-form-item label="客户权限" prop="customerFlagSwitch">
           <!--  <el-input v-model="form.customerFlag" placeholder="请输入客户启用标记，0未启用，1启用" /> -->
             <el-switch
               v-model="customerFlagSwitch"
               active-color="#13ce66"
               inactive-color="#ff4949">
             </el-switch>
             （如果启用则需要到用户管理进行分配客户）
           </el-form-item>
           <el-form-item label="负库存" prop="minusStockFlagSwitch">
           <!--  <el-input v-model="form.minusStockFlag" placeholder="请输入负库存启用标记，0未启用，1启用" /> -->
             <el-switch
               v-model="minusStockFlagSwitch"
               active-color="#13ce66"
               inactive-color="#ff4949">
             </el-switch>
             (如果启用则单据支持负库存，批次商品除外）
           </el-form-item>
         <!--  <el-form-item label="租户id" prop="tenantId">
             <el-input v-model="form.tenantId" placeholder="请输入租户id" />
           </el-form-item>
           <el-form-item label="删除标记，0未删除，1删除" prop="deleteFlag">
             <el-input v-model="form.deleteFlag" placeholder="请输入删除标记，0未删除，1删除" />
           </el-form-item> -->
         </el-form>
        <!-- <div slot="footer" class="dialog-footer">
           <el-button type="primary" @click="submitForm">确 定</el-button>
           <el-button @click="cancel">取 消</el-button>
         </div> -->
  </el-row>
</el-card>

  </div>
</template>

<script>
import { getInfoBytenantId,updateCompanyconfig } from "@/api/system/companyconfig";

export default {
  name: "Companyconfig",
  data() {
    return {
      depotFlagSwitch:false,
      minusStockFlagSwitch:false,
      customerFlagSwitch:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 系统参数表格数据
      companyconfigList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: null,
        companyContacts: null,
        companyAddress: null,
        companyTel: null,
        companyFax: null,
        companyPostCode: null,
        depotFlag: null,

        customerFlag: null,
        minusStockFlag: null,
        tenantId: null,
        deleteFlag: null
      },
      // 表单参数
      form: {depotFlagSwitch:false},
      // 表单校验
      rules: {
        companyName: [
          { required: true, message: "名称不能为空", trigger: "blur" },]

      }
    };
  },
  created() {

    this.reset();
    this.getInfo();
  },
  methods: {

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        companyName: null,
        companyContacts: null,
        companyAddress: null,
        companyTel: null,
        companyFax: null,
        companyPostCode: null,
        depotFlag: null,
        customerFlag: null,

        minusStockFlag: null,

        tenantId: null,
        deleteFlag: null
      };
      this.resetForm("form");
      this.depotFlagSwitch=false;
      this.minusStockFlagSwitch=false;
      this.customerFlagSwitch=false;
    },
    getInfo() {
      getInfoBytenantId().then(response => {
        this.form = response.data;
        this.depotFlagSwitch=this.form.depotFlag==1?true:false;

        this.customerFlagSwitch=this.form.customerFlag==1?true:false;

        this.minusStockFlagSwitch=this.form.minusStockFlag==1?true:false;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.depotFlag=this.depotFlagSwitch==true?1:0;
          this.form.customerFlag=this.customerFlagSwitch==true?1:0;
          this.form.minusStockFlag=this.minusStockFlagSwitch==true?1:0;
        updateCompanyconfig(this.form).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
        });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除系统参数编号为"' + ids + '"的数据项？').then(function() {
        return delCompanyconfig(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/companyconfig/export', {
        ...this.queryParams
      }, `companyconfig_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
